package com.recruit.screen.core;

import cn.hutool.core.util.ObjectUtil;
import cn.hutool.http.HttpStatus;

import java.io.Serializable;
import java.util.HashMap;

/**
 * 统一响应模板
 */
public class AjaxResult extends HashMap {

    private static final Serializable serialVersionUID = 1L;

    private static final String CODE_TAG = "code";

    private static final String MSG_TAG = "msg" ;

    private static final String DATA_TAG = "data" ;

    public AjaxResult(int code, String msg, Object data){
        super.put(CODE_TAG,code);
        super.put(MSG_TAG,msg);
        if (ObjectUtil.isNotEmpty(data)){
            super.put(DATA_TAG,data);
        }
    }

    public static AjaxResult success(){
        return AjaxResult.success("操作成功");
    }

    public static AjaxResult success(String msg){
        return new AjaxResult(HttpStatus.HTTP_OK,msg,null);
    }

    public static AjaxResult success(Object data){
        return AjaxResult.success("操作成功",data);
    }

    public static AjaxResult success(String msg ,Object data){
        return new AjaxResult(HttpStatus.HTTP_OK,msg,data);
    }

    public static AjaxResult error(){
        return AjaxResult.error("操作失败");
    }

    public static AjaxResult error(String msg){
        return new AjaxResult(HttpStatus.HTTP_INTERNAL_ERROR,msg,null);
    }

    public static AjaxResult error(String msg ,Object data){
        return new AjaxResult(HttpStatus.HTTP_INTERNAL_ERROR,msg,data);
    }

    public static AjaxResult error(int code,String msg ){
        return new AjaxResult(code,msg,null);
    }

}
